#pragma once

#include<torch/torch.h>
#include<memory>
#if defined(SWIG)
#endif
struct NoGrad {
	
	NoGrad() : torch_autograd_status(torch::autograd::GradMode::is_enabled()) {
		torch::autograd::GradMode::set_enabled(false);
	}
	~NoGrad() {
		java_close_support();
	}
	void java_close_support() noexcept(false) {
		torch::autograd::GradMode(torch_autograd_status);
	}

#if defined(SWIG)
	%javamethodmodifiers NoGrad::java_close_support      "private";
	%proxycode %{
@Override
public 	void close() throws java.lang.RuntimeException{
	java_close_support();
}
	%}
#endif
private:
	bool torch_autograd_status;
};